//
//  ReportArticleToastController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/20.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "ReportArticleToastController.h"
#import "FrouToastController.h"

@interface ReportArticleToastController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSoure;

@end

@implementation ReportArticleToastController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
}
-(void)createUI{
    self.isHidenNaviBar = YES;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15,15)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.view.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.view.layer.mask = maskLayer;

    
    UIView * headerView = [self createHeaderView];
    headerView.backgroundColor = KWhiteColor;
    
    UIView * footView = [self createFootView];
    footView.backgroundColor = KWhiteColor;

    [self.view addSubview:headerView];
    [self.view addSubview:footView];
    
    [self.view addSubview:self.listView];

    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    [footView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];

    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(headerView.mas_bottom);
        make.bottom.mas_equalTo(footView.mas_top);
    }];
}

#pragma mark ---UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSoure.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    cell.textLabel.textColor = UIColorFromRGB(0x273323);
    cell.textLabel.font = PingFangSC_Medium(14);
    cell.textLabel.text = self.dataSoure[indexPath.row];
    
    UIImageView * image = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"more")];
    [cell.contentView addSubview:image];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
    }];
    
    if (indexPath.row == self.dataSoure.count - 1) {
        image.hidden = NO;
    }else{
        image.hidden = YES;
    }
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (KScreenHeight - 100 - 100)/self.dataSoure.count;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.dataSoure.count - 1 == indexPath.row) {
        PresentationObject * object = [PresentationObject sharedPresentationObject];
//        object.alpha_bgView = 1;
        object.subViewFrame = CGRectMake(0, KScreenHeight-240, KScreenWidth, 240);
        FrouToastController * vc = [FrouToastController new];
        kWeakSelf(weakSelf);
        vc.releseBlock = ^{
            [weakSelf backBtnClicked];
        };
        [object showPresentingViewController:self PresentedViewController:vc];
    }else{
        [self backBtnClicked];
    }
}
-(void)backBtnClicked{
    [super backBtnClicked];
    BlockSafeRun(self.backBlck);
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[UITableView new];
        _listView.delegate =self;
        _listView.dataSource = self;
        _listView.scrollEnabled = NO;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
        _listView.separatorColor = SeparatorColor;
        _listView.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
    }
    return _listView;
}
-(NSMutableArray *)dataSoure{
    if (!_dataSoure) {
        _dataSoure =[[NSMutableArray alloc] initWithObjects:@"标题夸张",@"色情低俗",@"错别字多",@"旧闻重复",@"广告软文",@"内容不实",@"涉嫌违法犯罪",@"侵权（抄袭，侵犯名誉等）",@"其他问题，我要吐槽", nil];
    }
    return _dataSoure;
}
-(UIView *)createHeaderView{
    UIView * view = UIView.new;
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:IMAGE_NAMED(@"back") forState:UIControlStateNormal];
    kWeakSelf(weakSelf);
    [button addActionHandler:^{
        [weakSelf backBtnClicked];
    }];
    
    
    UILabel * label = UILabel.new;
    label.text = @"举报文章问题";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = PingFangSC_Medium(16);
    label.textColor = UIColorFromRGB(0x273323);
    
    [view addSubview:button];
    [view addSubview:label];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(0);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}


-(UIView *)createFootView{
    UIView * view = UIView.new;
    
    UILabel * label = UILabel.new;
    label.text = @"完成";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = PingFangSC_Medium(16);
    label.textColor = UIColorFromRGB(0x273323);
    
    [view addSubview:label];
    
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backBtnClicked)]];

    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}
@end
